******************************
** Graphs using CEIC data ****
******************************

* 0. Load data

use "${data}\CEICdataReplication.dta", clear
tsset time

* 1. Graphs

preserve
drop if yr < 2016 | yr > 2021

twoway scatter charcoalprice time, tline(2018m2)  
graph export "${figures}\PricesLongRun.eps", replace
twoway scatter charcoalprice time if yr < 2020, tline(2018m2)
graph export "${figures}\PricesShortRun.eps", replace


twoway scatter lnpricebread lnpricepetrol time, tline(2018m2)
graph export "${figures}\FoodPricesLongRun.eps", replace
twoway (scatter lnprice  lnpricepetrol time if yr < 2020) (scatter lnpricebread time if yr < 2020, yaxis(2)), tline(2018m2)
graph export "${figures}\FoodPricesShortRun.eps", replace

twoway scatter realcharcoalp time, tline(2018m2)
graph export "${figures}\RealpriceLongRun.eps", replace
twoway scatter realcharcoalp time if yr < 2020, tline(2018m2)
graph export "${figures}\RealpriceShortRun.eps", replace
restore

* 2. Regressions: following RD in time recommendations from hausman

local main lagug lagken post trend

drop if yr < 2015 | yr > 2019
sort time
gen trend = _n
gen posttrend = post*trend
replace posttrend = posttrend - 38 if posttrend > 0
gen trendsq = trend^2
gen posttrend2 = posttrend^2
la var posttrend "Trend after Feb. 2018"

tab post
bysort post: sum posttrend
sort time

newey lnprice `main', lag(2)
est sto c1
newey lnprice `main' posttrend, lag(2)
est sto c2
newey lnprice `main' posttrend trendsq posttrend2, lag(2)
est sto c3
newey lnprice `main' posttrend trendsq posttrend2 l.lnprice, lag(2)
est sto c4
newey lnprice `main' posttrend if yr > 2016 & yr < 2019, lag(2)
est sto c6
newey lnprice `main' posttrend l.lnprice if yr > 2016 & yr < 2019, lag(2)
est sto c7

newey lnprice `main' posttrend trendsq posttrend2, lag(3)

esttab c* using  "${tables}\TbCharcoalPrice.tex", replace ///
se nonotes  style(tex)  b(%12.3f) se(%12.3f)  stats(N, labels(Obs)  fmt(%12.0gc)) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "") ///
	keep (post posttrend) nonumbers fragment  ///
	 prehead({ \begin{tabular}{lcccccc}    ///
	 \hline \hline ///
	& (1) & (2) & (3) & (4) & (5)  & (6)  \\  ) ///
	prefoot( Time trend & linear & linear & square & square & linear & linear \\ ///
	Controls & yes & yes & yes & yes & yes & yes \\  ///
	Lags of dep var & 0 & 0 & 0 & 1 &  0  & 1 \\ ) ///
	  postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{ The dependent variable is the natural log transformation of the real charcoal price.  The estimator is ordinary least squares (OLS), and each column represents a different estimation.  All regressions include the lagged value of monthly rainfall in Kenya and Uganda. Columns (6) and (7) use a reduced analysis window from January 2017 to December 2018.  All other columns use data from January 2015 to December 2019. Standard errors are Newey-West with two lags. Treatment begins in March 2018. * p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )
estimates clear

preserve

replace post = 1 if time == 697
replace posttrend = post*trend
replace posttrend = posttrend - 38 if posttrend > 0
replace posttrend2 = posttrend^2
la var post "After January 2018"
la var posttrend "Trend after Jan. 2018"
tab post
bysort post: sum posttrend
sort time


newey lnprice `main', lag(2)
est sto c1
newey lnprice `main' posttrend, lag(2)
est sto c2
newey lnprice `main' posttrend trendsq posttrend2, lag(2)
est sto c3
newey lnprice `main' posttrend trendsq posttrend2 l.lnprice, lag(2)
est sto c4
newey lnprice `main' posttrend if yr > 2016 & yr < 2019, lag(2)
est sto c6
newey lnprice `main' posttrend l.lnprice if yr > 2016 & yr < 2019, lag(2)
est sto c7

newey lnprice `main' posttrend trendsq posttrend2, lag(3)

esttab c* using  "${tables}\TbCharcoalPriceFeb.tex", replace ///
se nonotes  style(tex)  b(%12.3f) se(%12.3f)  stats(N, labels(Obs)  fmt(%12.0gc)) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "") ///
	keep (post posttrend) nonumbers fragment  ///
	 prehead({ \begin{tabular}{lcccccc}    ///
	 \hline \hline ///
	& (1) & (2) & (3) & (4) & (5)  & (6)  \\  ) ///
	prefoot( Time trend & linear & linear & square & square & linear & linear \\ ///
	Controls & yes & yes & yes & yes & yes & yes \\  ///
	Lags of dep var & 0 & 0 & 0 & 1 &  0  & 1 \\ ) ///
	  postfoot(\hline \hline \end{tabular} } \begin{tablenotes}[para,flushleft] \footnotesize{The dependent variable is the natural log transformation of the real charcoal price.  The estimator is ordinary least squares (OLS), and each column represents a different estimation.  All regressions include the lagged value of monthly rainfall in Kenya and Uganda. Columns (6) and (7) use a reduced analysis window from January 2017 to December 2018.  All other columns use data from January 2015 to December 2019. Standard errors are Newey-West with two lags. Treatment includes February 2018. * p $<$.10, ** p$<$ .05, *** p$<$.01. } \end{tablenotes} )
estimates clear


restore

* 3. Placebo tests

sort time
tsset time
foreach x in bread petrol {

newey lnprice`x' `main' posttrend  , lag(2) force
est sto c1`x'
newey lnprice`x' `main' posttrend  l.lnprice`x', lag(2) force
est sto c2`x'    
newey lnprice`x' `main' posttrend trendsq posttrend2, lag(2) force
est sto c3`x'
newey lnprice`x' `main' posttrend trendsq posttrend2 l.lnprice`x', lag(2) force
est sto c4`x'

}

esttab c*bread c*petrol using  "${tables}\PlaceboPrices.tex", replace ///
se nonotes  style(tex)  b(%12.3f) se(%12.3f)  stats(N, labels(Obs)  fmt(%12.0gc)) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label mlabels("" "" "" "" "" "" "" "") ///
	keep (post posttrend) nonumbers fragment  ///
	 prehead({ \begin{tabular}{lcccccccc}    ///
	 \hline \hline ///
	 &  \multicolumn{4}{c}{Bread} &  \multicolumn{4}{c}{Petrol} \\ ///
	& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8)  \\ ) ///
	prefoot( Time trend & linear & linear & square & square & linear & linear & square & square \\ ///
	Controls & yes & yes & yes & yes & yes & yes & yes & yes \\  ///
	Lags of dep var & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1  \\ ) ///
	  postfoot(\hline \hline \end{tabular}} \begin{tablenotes}[para,flushleft] \footnotesize{The dependent variable is the natural log transformation of the real price listed in the table header. Columns (1)-(4) are prices of bread, and columns (5)-(8) prices of petrol.  The estimator is ordinary least squares (OLS), and each column represents a different estimation.  All regressions include the lagged value of monthly rainfall in Kenya and Uganda and a linear time trend. The window of analysis is from January 2016 to December of 2019. Standard errors are Newey-West with two lags. * p $<$.10, ** p$<$ .05, *** p$<$.01.} \end{tablenotes} )

estimates clear
